/**
 * @Author: An Bui
 * @Email: btan@tma.com.vn - anbuithien@gmail.com
 * @Date: Oct-31-2012 
 */

dojo.provide("webapp.iclifesize.dataBase");
dojo.declare("webapp.iclifesize.dataBase",null,{

	arrAppBarButtons : [],			// Array appbar button with specify status
	BACK : "BACK_BTN",				// BACK button
	LOGIN : "LOGIN_BTN",				// LOGIN button
	STATUS_LOGIN : 0,				// STATUS LOGIN
	STATUS_NONE : 1,
	NB_STATUS : 2,					// Number of status
	currStatusAppBar : 0,			// Current Status of AppBar
	isLoginView : true,				// flat of Login View		
	/**
	 * Constructor 
	 */
	constructor : function(){
		var that = this;
		alert("DataBase initializing");
		that.populateAppBar();
		alert("DataBase called");
	},
	
	/**
	 * populate Appbar Button
	 * load Button with corressponding status 
	 */
	populateAppBar : function() {
		var that = this;
		var func = dojo.hitch(webapp.iclifesize, webapp.iclifesize.onButtonPress);
		var arrButtons = [];
		
		// LOGIN VIEW
		arrButtons.push({
			strButtonName: that.LOGIN,							// Button indentifier
			strButtonLabel: _("Login", "webapp.iclifesize"),	// Label displayed
			strButtonIcon: "",									// CSS class of the image button
			callback: func										// Callback function called
		});
		
		that.arrAppBarButtons[that.STATUS_LOGIN] = arrButtons;
		arrButtons = [];
		that.arrAppBarButtons[that.STATUS_NONE] = [];
		
		for (var i=0; i < that.NB_STATUS; i++) {
			var appBar = ICTouchAPI.AppBarServices.getAppBar("iclifesize", "iclifesizestatus"+i);
			for (var j in that.arrAppBarButtons[i]) {
				var objButton = new UIElements.AppButton.AppButtonControl(that.arrAppBarButtons[i][j]);
				appBar.addActionButton(objButton);
			}
		};
	},
	
	/**
	 * updateAppBar
	 * update AppBar with a specify status
	 */
	updateAppBar : function(status) {
		var that = this;
		that.currStatusAppBar = status;
		
		// Create a statis button
		var func = dojo.hitch(webapp.iclifesize, webapp.iclifesize.onButtonPress, that.BACK);
		ICTouchAPI.AppBarServices.addExitButton(
			"iclifesize",
			"iclifesizestatus"+status,
			that.isLoginView,
			func
		);
		
		// Register actions bar buttons according to state
		ICTouchAPI.AppBarServices.setAppBar("iclifesize", "iclifesizestatus"+status, "getIclifesize");
	},
});
